package com.dubito.retrofit

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import com.dubito.retrofit.api.UserMgrService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import okhttp3.Dispatcher
import okhttp3.OkHttpClient
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


class MainActivity : AppCompatActivity() {

    private lateinit var retrofit: Retrofit

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        retrofit = Retrofit.Builder().baseUrl(my)
            .client(OkHttpClient().newBuilder().addInterceptor(HttpInterceptor()).build())
            .addConverterFactory(GsonConverterFactory.create()).build()
    }

    fun pwdLogin(view: View) {
        val create = retrofit.create(UserMgrService::class.java)
        MainScope().launch {
            val officialAccount = create.pwdLogin(PwdLoginReq("18818429658", "2ZM5ma73"))
            Log.d("A", officialAccount.toString())

        }

    }

    companion object {
        const val WAN_ANDROID = "https://wanandroid.com"
        const val my = "http://47.115.122.151:8182"
    }
}
